package org.algorithm.wE1.链表;

import org.algorithm.common.ListNode;

/**
 * @Date 2022/2/16 17:17
 */
public class 快慢指针寻找中间节点 {
    public static void main(String[] args) {
        int[] arr = {1,2,3,4,5};
        ListNode node =ListNode.build(arr);
        System.out.println(获取中间节点(node).val);
    }

    public static ListNode 获取中间节点(ListNode node){
        if(node == null || node.next == null){
            return node;
        }
        ListNode s = node;
        ListNode f = node;
        while (f.next!=null&&f.next.next!=null){
            s = s.next;
            f = f.next.next;
        }
        return s;
    }
}
